package com.travel.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.travel.pojo.dto.HotelDTO;
import com.travel.pojo.dto.HotelQueryDTO;
import com.travel.pojo.dto.PageDTO;
import com.travel.pojo.entity.Hotel;
import com.travel.pojo.vo.HotelVO;
import com.travel.service.IHotelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController("adminHotelController")
@RequiredArgsConstructor
@RequestMapping("/admin/hotel")
@CrossOrigin
public class HotelController {

    private final IHotelService hotelService;

    @PostMapping("/list")
    public PageDTO<HotelVO> pageListHotel(@RequestBody HotelQueryDTO hotelQueryDTO){
        return hotelService.pageListHotel(hotelQueryDTO);
    }

    @PostMapping("/createHotel")
    public void createHotel(@RequestBody HotelDTO hotelDTO){
        String image = hotelDTO.getImage();
        Hotel hotel = BeanUtil.copyProperties(hotelDTO, Hotel.class);
        hotel.setPhotoUrl(image);
        hotelService.save(hotel);
    }


    public void deleteHotel(){

    }
    @PutMapping("/updateHotel/{id}")
    public void updateHotel(@PathVariable Long id, @RequestBody HotelDTO hotelDTO){
        hotelService.updateHotel(id, hotelDTO);
    }



}
